import {
  createSlice,
} from "@reduxjs/toolkit";
const countSlice = createSlice({
  //命名空间 name值作为action type的前缀
  name: "counter",
  // 初始值
  initialState: {
    count: 0,
  },
  //定义reducer更新状态函数,  组件中dispatch使用的action函数
  reducers: {
    increment(prev, action) {
      prev.count += action.payload
    },
    decrement(prev, action) {
      prev.count -= action.payload
    }
  }
})

export default countSlice.reducer

export const { increment, decrement } = countSlice.actions